clear; close all;


% event window
NOBS_before = 24;
NOBS_after  = 10*12;


% load crisis simulation
load crisis_simulation_out.mat MOM4 MOM7


% Figure 3
ff = figure('Position', [100, 100, 800, 380]);
set(ff,'Units','Inches');
pos = get(ff,'Position');
set(ff,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)])
subplot = @(m,n,p)subtightplot(m, n, p, [0.09 0.09], [0.21 0.08], [0.04 0.01]);

% load data
r_dates   = floor(xlsread('../data/CRSP_m.xlsx','B3:B1142')/100);
rx        = xlsread('../data/CRSP_m.xlsx','D3:D1142');
cpi_dates = (1:12)'+(1913:2021)*100;
cpi_dates = cpi_dates(:);
cpi       = xlsread('../data/CPI.xlsx','D13:D1320');
[dates,i1,i2] = intersect(r_dates,cpi_dates);
rx = rx(i1);
cpi = cpi([i2(1)-1;i2]);
rx = log(1+rx)-diff(log(cpi));
price = exp(cumsum(rx(dates>=192901&dates<=193612)));
price = price./price(12);
default_rates = xlsread('../data/defaults.xlsx','B11:K19');
clear i1 i2 r_dates cpi_dates cpi

subplot(1,2,1);
plot((-11:84)/12,price,'r','LineWidth',1.5); hold on; grid on
plot((-NOBS_before:NOBS_after-1)/12,mean(MOM7,2),'k:','LineWidth',1.5);
axis([-1,7,0.2,1.5])
grid on; set(gca,'FontSize',12);
title('Equity Index','FontSize',15);
xlabel('Event Time (Years)','FontSize',15);
leg=legend('Data','Model','Location','NE','Orientation','horizontal'); set(leg,'FontSize',13,'box','on');
leg.Position(1) = leg.Position(1) + 0.173;
leg.Position(2) = leg.Position(2) -0.82;

subplot(1,2,2);
bar((-1:7)+0.5,default_rates(:,4),'r'); hold on;
plot((-NOBS_before:NOBS_after-1)/12,mean(MOM4,2),'k:','LineWidth',1.5); set(gca,'FontSize',12);
title('Default Probability, % p.a.','FontSize',15); xlim([-1,7]); grid on; xlabel('Event Time (Years)','FontSize',15); ylim([0,3.7]);

print(gcf,'figure_3','-dpdf','-r0')



